/**
 * 按钮权限管理
 * @author WangLongFei/Alisdon [920124512@qq.com]
 */
export default {
  namespaced: true,
  state: {
    permisstion: []
  },
  getters: {
    getPerm(state) {
      return state.permisstion;
    }
  },
  actions: {
    setPermission({ commit }, permisstion) {
      if (Array.isArray(permisstion)) {
        commit('mergeState', { permisstion });
      } else {
        throw new TypeError('permisstion is not Array');
      }
    }
  },
  mutations: {
    /**
     * 通用改变状态的值
     * @param {Object} state        状态
     * @param {Object} mergeObject  需要改变的对象 {key: value}
     */
    mergeState(state, mergeObject) {
      for (const key in mergeObject) {
        state[key] = mergeObject[key];
      }
    }
  }
};
